Use the stencil buffer to control which fragments Kanzi renders. You can use the stencil buffer to mask areas in the framebuffer and then use stencil testing to discard or accept fragments depending on the mask.
To use the stencil buffer to mask 3D nodes with other 3D nodes:










Use the Stencil Test Function property to compare the Stencil Function Reference Value to the value in the stencil buffer.
You can use these operations:
| Stencil Test Function | Description |
|---|---|
| Always | Pass always |
| Equal | Pass if the values are equal |
| Greater | Pass if Stencil Function Reference Value is greater than the value in the stencil buffer |
| Greater or Equal | Pass if Stencil Function Reference Value is greater than or equal to the value in the stencil buffer |
| Less | Pass if Stencil Function Reference Value is less than the value in the stencil buffer |
| Less or Equal | Pass if Stencil Function Reference Value is less than or equal to the value in the stencil buffer |
| Never | Fail always |
| Not equal | Pass if Stencil Function Reference Value is different from the value in the stencil buffer |
You can use the Stencil Function Mask property to perform a bitwise AND operation on the Stencil Function Reference Value and the value in the stencil buffer before comparing them with the Stencil Test Function. This way you can modify only certain bits in the stencil buffer. By default, and when Stencil Function Mask is set to 255, all Stencil Test Function operations both read and write all bits in the buffers.
For example, if you set Stencil Function Mask to 2, Kanzi Studio preserves only the second bit of the stencil reference value and the stencil buffer value. This way you can use different bits of the stencil buffer to mask different elements on the screen.
Use the Stencil Fail Operation, Stencil Pass Depth Fail Operation and Stencil Pass Depth Pass Operation properties to set the values in the stencil buffer depending on the results of stencil and depth test. By default Kanzi Studio keeps the current value.
You can use these operations:
| Operation | Description |
|---|---|
| Decrease | If the stencil value if larger than 0, decrease it by 1. |
| Decrease wrap | Otherwise the same as Decrease, but if the current value is 0, set the value to the maximum possible value for the stencil buffer, usually 255. |
| Increase | If the stencil value is lower than the maximum value, increase it by 1. |
| Increase wrap | Otherwise the same as Increase, but if the maximum value is exceeded, set the value to 0. |
| Invert | Apply a bitwise invert to the value. |
| Keep | Keep the current value. |
| Replace | Replace the stencil value with the value of the Stencil Function Reference Value property. |
| Zero | Set the stencil value to 0. |